/*
 * Copyright (C) 2017 Fabian Terhorst
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file kt in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.fabianterhorst.isometric.shapes;

import io.fabianterhorst.isometric.Path;
import io.fabianterhorst.isometric.Point;
import io.fabianterhorst.isometric.Shape;

/**
 * Pyramid Class.
 *
 * @since 03.03.21
 */
public class Pyramid extends Shape {
    /**
     * Constructor
     *
     * @param origin {@link Point}
     */
    public Pyramid(Point origin) {
        this(origin, 1, 1, 1);
    }

    /**
     * Constructor
     *
     * @param origin {@link Point}
     * @param dx {@link double}
     * @param dy {@link double}
     * @param dz {@link double}
     */
    public Pyramid(Point origin, double dx, double dy, double dz) {
        super();

        Path[] paths = new Path[4];

        /**
         * Path parallel to the x-axis
         */
        Path face1 = new Path(new Point[] {
            origin, new Point(origin.getX() + dx, origin.getY(), origin.getZ()),
            new Point(origin.getX() + dx / 2.0, origin.getY() + dy / 2.0, origin.getZ() + dz)
        });

        /**
         * Push the face, and its opposite face, by rotating around the Z-axis
         */
        paths[0] = face1;
        paths[1] = face1.rotateZ(origin.translate(dx / 2.0, dy / 2.0, 0), Math.PI);
        /**
         * Path parallel to the y-axis
         */
        Path face2 = new Path(new Point[] {
            origin, new Point(origin.getX() + dx / 2, origin.getY() + dy / 2, origin.getZ() + dz),
            new Point(origin.getX(), origin.getY() + dy, origin.getZ())
        });
        paths[2] = face2;
        paths[3] = face2.rotateZ(origin.translate(dx / 2.0, dy / 2.0, 0), Math.PI);
        setPaths(paths);
    }
}